if not exists (select * from sys.procedures where object_id = object_id(N'[foo].[define_SeedData_foo_bar]'))
    exec sp_executesql N'create procedure [foo].[define_SeedData_foo_bar] as begin return 0; end';
go
alter procedure [foo].[define_SeedData_foo_bar] (
    @foo_type nvarchar(max),
    @blah_blah nvarchar(max)
)
as
begin
    declare @foo_type_id_lookup int;
    select @foo_type_id_lookup = [id] from [foo].[foo_types] where [name] = @foo_type;

    if not exists (select * from [foo].[foo_bars] where [foo_type_id] = @foo_type_id_lookup)
    insert [foo].[foo_bars] ([foo_type_id],[blah_blah])
    values (@foo_type_id_lookup,@blah_blah);
    else
        update [foo].[foo_bars] set
            [blah_blah] = @blah_blah
        where [foo_type_id] = @foo_type_id_lookup;

    return 0;
end
go

exec [foo].[define_SeedData_foo_bar] @foo_type='foo',@blah_blah='bleep';
exec [foo].[define_SeedData_foo_bar] @foo_type='foo',@blah_blah='blarp';
go

if not exists (select * from sys.procedures where object_id = object_id(N'[foo].[define_SeedData_foo_other_bar]'))
    exec sp_executesql N'create procedure [foo].[define_SeedData_foo_other_bar] as begin return 0; end';
go
alter procedure [foo].[define_SeedData_foo_other_bar] (
    @foo_type nvarchar(max),
    @blah_blah nvarchar(max)
)
as
begin
    declare @foo_type_id_lookup int;
    select @foo_type_id_lookup = [id] from [foo].[foo_types] where [name] = @foo_type;

    insert [foo].[foo_other_bars] ([foo_type_id],[blah_blah])
    values (@foo_type_id_lookup,@blah_blah);

    return 0;
end
go

exec [foo].[define_SeedData_foo_other_bar] @foo_type='bar',@blah_blah='blarg';
exec [foo].[define_SeedData_foo_other_bar] @foo_type='bar',@blah_blah='hum';
go

if not exists (select * from sys.procedures where object_id = object_id(N'[foo].[define_SeedData_foo_map__for__foo_foo_bar_foo_type_id]'))
    exec sp_executesql N'create procedure [foo].[define_SeedData_foo_map__for__foo_foo_bar_foo_type_id] as begin return 0; end';
go
alter procedure [foo].[define_SeedData_foo_map__for__foo_foo_bar_foo_type_id] (
    @value int
)
as
begin
    insert [foo].[foo_maps] ([foo_type_id],[value])
    select [foo_type_id],@value from [foo].[foo_bars] where [foo_type_id] not in (select [foo_type_id] from [foo].[foo_maps]);


    return 0;
end
go

exec [foo].[define_SeedData_foo_map__for__foo_foo_bar_foo_type_id] @value=1;
exec [foo].[define_SeedData_foo_map__for__foo_foo_bar_foo_type_id] @value=2;
go

if not exists (select * from sys.procedures where object_id = object_id(N'[foo].[define_SeedData_foo_map__for__foo_foo_other_bar_foo_type_id]'))
    exec sp_executesql N'create procedure [foo].[define_SeedData_foo_map__for__foo_foo_other_bar_foo_type_id] as begin return 0; end';
go
alter procedure [foo].[define_SeedData_foo_map__for__foo_foo_other_bar_foo_type_id] (
    @value int
)
as
begin
    insert [foo].[foo_maps] ([foo_type_id],[value])
    select [foo_type_id],@value from [foo].[foo_other_bars] where [foo_type_id] not in (select [foo_type_id] from [foo].[foo_maps]);


    return 0;
end
go

exec [foo].[define_SeedData_foo_map__for__foo_foo_other_bar_foo_type_id] @value=3;
exec [foo].[define_SeedData_foo_map__for__foo_foo_other_bar_foo_type_id] @value=4;
go
